﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class GoodsLog
    {
        private readonly Chain.IDAL.GoodsLog dal = new Chain.IDAL.GoodsLog();

        public int Add(Chain.Model.GoodsLog model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.GoodsLog> DataTableToList(DataTable dt)
        {
            List<Chain.Model.GoodsLog> list = new List<Chain.Model.GoodsLog>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.GoodsLog item = new Chain.Model.GoodsLog();
                    if ((dt.Rows[i]["ID"] != null) && (dt.Rows[i]["ID"].ToString() != ""))
                    {
                        item.ID = int.Parse(dt.Rows[i]["ID"].ToString());
                    }
                    if ((dt.Rows[i]["GoodsAccount"] != null) && (dt.Rows[i]["GoodsAccount"].ToString() != ""))
                    {
                        item.GoodsAccount = dt.Rows[i]["GoodsAccount"].ToString();
                    }
                    if ((dt.Rows[i]["Type"] != null) && (dt.Rows[i]["Type"].ToString() != ""))
                    {
                        item.Type = int.Parse(dt.Rows[i]["Type"].ToString());
                    }
                    if ((dt.Rows[i]["GoodsID"] != null) && (dt.Rows[i]["GoodsID"].ToString() != ""))
                    {
                        item.GoodsID = int.Parse(dt.Rows[i]["GoodsID"].ToString());
                    }
                    if ((dt.Rows[i]["TotalPrice"] != null) && (dt.Rows[i]["TotalPrice"].ToString() != ""))
                    {
                        item.TotalPrice = decimal.Parse(dt.Rows[i]["TotalPrice"].ToString());
                    }
                    if ((dt.Rows[i]["GoodsNumber"] != null) && (dt.Rows[i]["GoodsNumber"].ToString() != ""))
                    {
                        item.GoodsNumber = int.Parse(dt.Rows[i]["GoodsNumber"].ToString());
                    }
                    if ((dt.Rows[i]["Remark"] != null) && (dt.Rows[i]["Remark"].ToString() != ""))
                    {
                        item.Remark = dt.Rows[i]["Remark"].ToString();
                    }
                    if ((dt.Rows[i]["CreateTime"] != null) && (dt.Rows[i]["CreateTime"].ToString() != ""))
                    {
                        item.CreateTime = DateTime.Parse(dt.Rows[i]["CreateTime"].ToString());
                    }
                    if ((dt.Rows[i]["ShopID"] != null) && (dt.Rows[i]["ShopID"].ToString() != ""))
                    {
                        item.ShopID = int.Parse(dt.Rows[i]["ShopID"].ToString());
                    }
                    if ((dt.Rows[i]["UserID"] != null) && (dt.Rows[i]["UserID"].ToString() != ""))
                    {
                        item.UserID = int.Parse(dt.Rows[i]["UserID"].ToString());
                    }
                    if ((dt.Rows[i]["ChangeShopID"] != null) && (dt.Rows[i]["ChangeShopID"].ToString() != ""))
                    {
                        item.ChangeShopID = int.Parse(dt.Rows[i]["ChangeShopID"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int ID)
        {
            return this.dal.Delete(ID);
        }

        public bool DeleteList(string IDlist)
        {
            return this.dal.DeleteList(IDlist);
        }

        public bool ExeclDataInput(ArrayList sqlArray)
        {
            return this.dal.ExeclDataInput(sqlArray);
        }

        public bool Exists(int ID)
        {
            return this.dal.Exists(ID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public int GetIDByGoodsAccount(string GoodsAccount)
        {
            return this.dal.GetIDByGoodsAccount(GoodsAccount);
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public DataSet GetListsss(string strWhere)
        {
            return this.dal.GetListsss(strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.GoodsLog GetModel(int ID)
        {
            return this.dal.GetModel(ID);
        }

        public List<Chain.Model.GoodsLog> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.GoodsLog model)
        {
            return this.dal.Update(model);
        }
    }
}

